package com.bcsp.xml;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.List;

public class Test10 {

    //xpath
    public static void main(String[] args) throws Exception {
        //获取文件路径
        String path = Test10.class.getClassLoader().getResource("game.xml").getPath();

        //b_out.xml
        //准备SAXReader
        SAXReader reader = new SAXReader();
        //读取文档
        Document document = reader.read(new File(path));
        Node titleNode = document.selectSingleNode("//channel/title");
        System.out.println(titleNode.getStringValue());
        List<Node> items = document.selectNodes("//channel/item");
        for (Node node : items){
            Element itemElement = (Element) node;
            System.out.println(itemElement.elementText("title"));
            System.out.println("\t"+itemElement.elementText("pubDate"));
        }
    }
}
